
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cookie: [],
    mate: null,
    https: "https://csb2c.fenxiangqu.cn/",
    newIndex: 1,
    spsl: 0,
    commnum: 1,
    win:false,
    iphone:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    var a = wx.getStorageSync('cookie') || [];
    this.setData({
      cookie: a
    })
    wx.request({
      url: "https://csb2c.fenxiangqu.cn/xcx_wx_commodityInt",
      data: {
        id: options.id
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'Cookie': "LID=" + self.data.cookie
      },
      method: "POST",
      success: res => {
        console.log(res.data)
        self.setData({
          mate: res.data,
          spsl: res.data[0].spkc
        })
      },
      fail: res => {
        wx.showToast({
          title: '网络故障！',
          icon: 'success',
          duration: 1000
        })
      }
    })
  },
  startOne: function (e) {
    const index = e.currentTarget.dataset.index;
    this.setData({
      newIndex: index

    })

  },
  checkWin:function(e){
      this.setData({
        win:true
      })
  },
  qx:function(e){
    this.setData({
      win: false
    })
  },
  ts:function(e){
    this.setData({
      iphone: e.detail.value
    })
  },
  sub:function(e){
    var self = this;
   const iphone =  this.data.iphone;
   const spid = e.currentTarget.dataset.id;
   console.log(e)
   if (iphone.length < 11){
     wx.showToast({
       title: '联系号码有误！',
       icon: 'success',
       duration: 1000
     })
   }else{
     wx.request({
       url: "https://csb2c.fenxiangqu.cn/xcx_zb_000030x",
       data: {
         spid: spid,
         p:iphone
       },
       header: {
         'content-type': 'application/x-www-form-urlencoded',
         'Cookie': "LID=" + self.data.cookie
       },
       method: "POST",
       success: res => {
         if(res.data=="login"){
           wx.showModal({
             title: '登录提示',
             content: '您未登录，是否前往登录？',
             success: function (res) {
               if (res.confirm) {
                 wx.switchTab({
                   url: '../center/center'
                 })
               } else if (res.cancel) {
                 console.log('用户点击取消')
               }
             }
           })
         }else{
           if (res.data == "NO") {
             wx.showToast({
               title: '已提交,请耐心等候客服回复',
               icon: 'success',
               duration: 1000
             })
           } else if (res.data == "OK") {
             wx.showToast({
               title: '提交成功,请耐心等候客服回复',
               icon: 'success',
               duration: 1000
             })
           }
         }
       },
       fail: res => {
         wx.showToast({
           title: '网络故障！',
           icon: 'success',
           duration: 1000
         })
       }
     })
   }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})